package com.myframe.demo.service;

import java.io.IOException;
import java.util.List;
import java.util.Vector;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.common.jdbc.DB4ObjUtil;
import com.common.jdbc.DBBeanUtil;
import com.common.pager.PageHelper;
import com.myframe.demo.vo.DbTest;
import com.myframe.demo.vo.DemoVO;
import com.myframe.demo.vo.MsgQuester;

public class DemoService implements IDemoService {
	private Logger log = Logger.getLogger(this.getClass());
	public DemoVO sayHello(String name){
		DemoVO vo = new DemoVO("1","hello:"+name);
		log.info("hello:"+name);
		return vo;
	}
	public String say(){
		System.out.println("say=====");
		return "hello world!";
	}
	public List<MsgQuester> find1(PageHelper pager){
		StringBuilder sql = new StringBuilder("select * from DB_TEST");
		sql.append(" order by ID desc");
		Vector<MsgQuester> list=null;
		try {
			list = DBBeanUtil.executePager4Obj(new DbTest(), sql.toString(), pager);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	}
	public List<MsgQuester> find(PageHelper pager){
		StringBuilder sql = new StringBuilder("select * from DB_TEST");
		sql.append(" order by ID desc");
		Vector<MsgQuester> list=null;
		try {
			list = DB4ObjUtil.executePager4Obj(new DbTest(), sql.toString(), pager);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	}
	
	

	public static Document getXMLData() throws IOException {   
        Document document = DocumentHelper.createDocument();   
       // document.setXMLEncoding("GB18030");   
       
        Element root = document.addElement("tree");   
        root.addAttribute("id", "0");   
  
        Element item = root.addElement("item");   
        item.addAttribute("text", "省内网站链接");   
        item.addAttribute("id", "friendnet"); 
        item.addAttribute("open", "1"); 
        item.addAttribute("im0", "folderOpen.gif"); 
        item.addAttribute("im1", "folderOpen.gif"); 
        item.addAttribute("im2", "folderClosed.gif"); 
        for (int i = 0,j = 10;i<j ; i++) {
        	 Element subItem = item.addElement("item");   
             subItem.addAttribute("text", "item"+i);   
             subItem.addAttribute("id", 1+String.valueOf(i)); 
             /*Element subItem1 = subItem.addElement("userdata ");
             subItem1.addAttribute("name","url");
             subItem1.addComment(friendnet[i].getAddress());*/
		}
        
        Element item1 = root.addElement("item"); 
        item1.addAttribute("text", "省外网站链接");   
        item1.addAttribute("id", "outnet"); 
        item1.addAttribute("open", "1"); 
        item1.addAttribute("im0", "folderOpen.gif"); 
        item1.addAttribute("im1", "folderOpen.gif"); 
        item1.addAttribute("im2", "folderClosed.gif"); 
        for (int i = 0,j = 10;i<j ; i++) {
       	 Element subItem = item1.addElement("item");   
            subItem.addAttribute("text", "item"+i);   
            subItem.addAttribute("id", 2+String.valueOf(i)); 
            /*Element subItem1 = subItem.addElement("userdata ");
            subItem1.addAttribute("name","url");
            subItem1.addComment(friendnet[i].getAddress());*/
		}
        
        return document;   
  
    }  
}
